package flst.ipiweb.struts.action.envoicolis;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import flst.ipiweb.service.ServiceCommande;
import flst.ipiweb.transverse.Commande;
import flst.ipiweb.transverse.IPIException;

public class EnvoyerColisAction extends Action{
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form,
			HttpServletRequest request, 
			HttpServletResponse response)
			throws Exception {
		
			//On récupère la session
			HttpSession session = request.getSession();
			if(session.getAttribute("login") == null)
			{
				return mapping.findForward("login");
			}
		
			int idCommande = 0;
			idCommande = Integer.parseInt(request.getParameter("id"));
			
			ServiceCommande sCommande = new ServiceCommande();
			
			try
			{
				Commande commande = new Commande();
				commande.setIdCommande(idCommande);
				sCommande.envoyerCommande(commande);
				
			}
			catch(IPIException e)
			{
				System.out.println(e.getMessage());
			}
			
			
			return mapping.findForward("login");
		}

}
